﻿/*
 * Copyright (c) 2011 Shawn Rakowski
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to 
 * deal in the Software without restriction, including without limitation the 
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 * sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 * SOFTWARE. 
 * 
 */

using System;
using System.Collections.Generic;

namespace ROS.Application.DomainObjects
{
    internal class MenuItem : DomainObject
    {
        #region Fields

        private long id;
        private String name;
        private bool isActive;
        private bool isBackendFulfilled;
        private Money price;
        private List<MenuCategory> menuCategories;
        private List<OrderItem> orderItems;

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the ID of this MenuItem.
        /// </summary>       
        public long ID
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        /// Gets or sets whether or not this menu item is active.
        /// </summary>
        public bool IsActive
        {
            get { return isActive; }
            set { isActive = value; }
        }

        /// <summary>
        /// Gets or sets the name of this menu item.
        /// </summary>        
        public String Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// Gets or sets the fulfillment location of this menu item.
        /// </summary>        
        public bool IsBackendFulfilled
        {
            get { return isBackendFulfilled; }
            set { isBackendFulfilled = value; }
        }

        /// <summary>
        /// Gets or sets the price of this menu item.
        /// </summary>
        public Money Price
        {
            get { return price; }
            set { price = value; }
        }

        /// <summary>
        /// Gets or sets a list of categories this menu item belongs to.
        /// </summary>
        public List<MenuCategory> MenuCategories
        {
            get { return menuCategories; }
            set { menuCategories = value; }
        }

        /// <summary>
        /// Gets a list of order items this menu item is attached to.
        /// </summary>
        public List<OrderItem> OrderItems
        {
            get 
            {
                if (orderItems == null)
                    orderItems = new List<OrderItem>();

                return orderItems;
            }
            set { orderItems = value; }
        }

        /// <summary>
        /// Gets whether or not this order item may be deleted.
        /// </summary>
        public bool MayBeDeleted 
        {
            get
            {
                return OrderItems.Count == 0;
            }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Construct an empty MenuItem object.
        /// </summary>
        public MenuItem()
        {
        }

        /// <summary>
        /// Construct a new MenuItem object.
        /// </summary>
        public MenuItem(String name, bool isBackendFulfilled,
                        Money price, List<MenuCategory> menuCategories)
        {
            id = 0;
            isActive = true;
            this.name = name;
            this.isBackendFulfilled = isBackendFulfilled;            
            this.price = price;
            this.menuCategories = menuCategories;
            this.orderItems = null;
        }

        /// <summary>
        /// Construct a new MenuItem object.
        /// </summary>
        public MenuItem(long id, bool isActive, String name, bool isBackendFulfilled)
        {
            this.id = id;
            this.isActive = isActive;
            this.name = name;
            this.isBackendFulfilled = isBackendFulfilled;
            this.price = null;
            this.menuCategories = null;
            this.orderItems = null;
        }

        /// <summary>
        /// Construct a new MenuItem object.
        /// </summary>
        public MenuItem(long id, bool isActive,
                        String name, bool isBackendFulfilled,
                        Money price)
        {
            this.id = id;
            this.isActive = isActive;
            this.name = name;
            this.isBackendFulfilled = isBackendFulfilled;
            this.price = price;
            this.menuCategories = null;
            this.orderItems = null;
        }

        /// <summary>
        /// Construct a new MenuItem object.
        /// </summary>
        public MenuItem(long id, bool isActive,
                        String name, bool isBackendFulfilled,
                        Money price, List<MenuCategory> menuCategories)
        {
            this.id = id;
            this.isActive = isActive;
            this.name = name;
            this.isBackendFulfilled = isBackendFulfilled;
            this.price = price;
            this.menuCategories = menuCategories;
            this.orderItems = null;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Deactivate this MenuItem
        /// </summary>
        internal void Deactivate()
        {
            isActive = false;
        }        
   
        #endregion
    }
}
